package com.card.game;

import java.util.Arrays;
import java.util.Collections;
import java.util.Vector;

public class Bing implements Comparable<Bing>{
	protected int index;
	protected Card c1;
	protected Card c2;
	protected int value;
	
	public Bing(int index,Card c1, Card c2) {
		this.index = index;
		this.c1 = c1;
		this.c2 = c2;
		this.value = getValue();
	}

	@Override
	public int compareTo(Bing o) {
		//负的小 正的大
		int v = this.getValue() - o.getValue();
		if(v == 0) {
			return this.index - o.index;
		}
		return v;
	}
	
	public int getValue() {
		if(c1.getBingIndex() == c2.getBingIndex()) {
			//是对
			return 10+c1.getBingIndex();
		}
		int v1 = c1.getBingIndex();
		int v2 = c2.getBingIndex();
		int v = v1 + v2;
		return v>=10?v-10:v;
	}
	
	public boolean isBaozi() {
		return c1.getBingIndex() == c2.getBingIndex();
	}
	
	
	@Override
	public String toString() {
		return "Bing [index=" + index + ", c1=" + c1 + ", c2=" + c2 + "]";
	}

	public static void main(String[] args) {
//		Vector<Card> tgg = CardUtils.createTGG();
//		Bing b1 = new Bing(1,CardUtils.faPaiOne(tgg), CardUtils.faPaiOne(tgg));
//		Bing b2 = new Bing(2,CardUtils.faPaiOne(tgg), CardUtils.faPaiOne(tgg));
//		System.out.println(b1.toString());
//		System.out.println(b2.toString());
//		int b = b1.compareTo(b2);
//		System.out.println(b);
		Vector<Bing> bs = new Vector<>();
		bs.add(new Bing(0, new Card(3, 1), new Card(3, 1)));
		bs.add(new Bing(1, new Card(3, 1), new Card(3, 1)));
		Collections.sort(bs);
		System.out.println(Arrays.toString(bs.toArray()));
	}
}
